package com.ffox.controller;

import com.ffox.entity.ForumComment;
import com.ffox.entity.ForumPost;
import com.ffox.service.UserForumService;
import com.ffox.service.dto.CommentDto;
import com.ffox.service.dto.PostDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/userForum")
public class UserForumController {
    @Autowired
    private UserForumService userForumService;
//    新增帖子
    @RequestMapping("/addPost")
    public Integer addPost(@RequestBody ForumPost post){
        System.out.println("userNum===========>"+post.getUserNum());
        return userForumService.addPost(post);
    }
//    获取所有的帖子
    @RequestMapping("/getAllPosts")
    public List<PostDto> getAllPosts(){
        return userForumService.getAllPosts();
    }
//    逻辑删除帖子
    @RequestMapping("/deletePost")
    public Integer deletePost(Long postId){
        return userForumService.deletePost(postId);
    }


//    为对应帖子添加评论
    @RequestMapping("/addComment")
    public Integer addComment(@RequestBody ForumComment comment){
        System.out.println(comment);
        return userForumService.addComment(comment);
    }
//    获取对应帖子对应的评论
    @RequestMapping("/getComments")
    public List<CommentDto> getComments(Long postId){
        return userForumService.getComments(postId);
    }
//    逻辑删除评论
    @RequestMapping("/deleteComment")
    public Integer deleteComment(Long commentId){
        System.out.println("commentId===========>"+commentId);
        return userForumService.deleteComment(commentId);
    }
}
